package edu.depaul.se.courseregistration.mdb.pubsub;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

/**
 * CourseUpdateTopicListener is the subscriber of jms/javaee6/Topic topic.
 *
 * @author xchen
 */
@MessageDriven(mappedName = "jms/javaee6/Topic", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
    @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
    @ActivationConfigProperty(propertyName = "clientId", propertyValue = "StudentBeanTopicListener"),
    @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "StudentBeanTopicListener")
})
public class StudentBeanTopicListener implements MessageListener {

    @Override
    public void onMessage(Message message) {
        TextMessage textMessage = (TextMessage) message;
        try {
            System.out.println("StudentBeanTopicListener:\n Message received:\n " + textMessage.getText());
        } catch (JMSException ex) {
            Logger.getLogger(StudentBeanTopicListener.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("MDB is not ready to subscribe messages from jms/javaee6/Topic:  " + ex.toString());
        }
    }
}
